package com.zx.idc.backend.gui.mo;


import com.baomidou.mybatisplus.plugins.Page;
import com.zx.idc.backend.gui.common.BaseApi;
import com.zx.idc.backend.gui.common.BasicServiceApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.backend.gui.common.base.BaseExcelApi;
import com.zx.idc.backend.gui.common.base.BaseNotDealTotalApi;
import com.zx.idc.backend.gui.common.base.BaseNotReportTotalApi;
import com.zx.idc.backend.gui.common.util.NetworkUtil;
import com.zx.idc.backend.gui.shiro.TokenManagerUtil;
import com.zx.idc.common.lang.tuple.Tuple4;
import com.zx.idc.ds.mo.bean.WarnList;
import com.zx.idc.ds.mo.entity.MoIllegalInfo;
import com.zx.idc.ds.mo.service.IMoIllegalInfoService;
import com.zx.idc.ds.mo.vo.MoIllegalInfoVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 非法信息 前端控制器
 * </p>
 *
 * @author rxliuli
 * @since 2019-03-08
 */
@RestController
@RequestMapping("/api/moIllegalInfo")
public class MoIllegalInfoController extends BasicServiceApi<IMoIllegalInfoService, MoIllegalInfo> implements BaseNotDealTotalApi<IMoIllegalInfoService, MoIllegalInfo>,BaseExcelApi<IMoIllegalInfoService, MoIllegalInfoVo> {
    @Autowired
    private IMoIllegalInfoService service;
    @Autowired
    private TokenManagerUtil tokenManagerUtil;

    @GetMapping("/query-page")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info")
    public Result<Page<MoIllegalInfoVo>> queryPage(Page<MoIllegalInfoVo> page, MoIllegalInfoVo entity) {
        return success(service.pageByParam(page, entity));
    }

    @GetMapping("/query-page-count")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info")
    public Result<Page<MoIllegalInfoVo>> queryPageCount(Page<MoIllegalInfoVo> page, MoIllegalInfoVo entity) {
        return success(service.pageCountByParam(page, entity));
    }

    @PostMapping("/delete/batch")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info:edit")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> idList) {
        return success(service.deleteBatchIds(idList));
    }

    /**
     * 批量处置监测设备
     *
     * @param tuple4 批量处置信息，分别是处置状态、日志操作、说明信息以及需要处置的监测设备 id 列表
     * @return 处置结果
     */
    @PostMapping("/handle-batch")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info:edit")
    public Result<Boolean> dealBatch(@RequestBody Tuple4<Integer, Integer, String, List<MoIllegalInfoVo>> tuple4, HttpServletRequest request) {
        return success(service.updateDealBatch(tokenManagerUtil.getCurrentUser().getId(), NetworkUtil.getIpAddress(request), tuple4));
    }

    @PostMapping("/cancel-handle-batch")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info:edit")
    public Result<Boolean> dealCancelBatch(@RequestBody List<MoIllegalInfoVo> moIllegalInfoVoList) {
        return success(service.updateDealCancelBatch(moIllegalInfoVoList, tokenManagerUtil.getCurrentUser().getId()));
    }

    @PostMapping("/set-trust")
    @RequiresPermissions("illegal-monitoring:mo-illegal-info:edit")
    public Result<Boolean> setTrust(@RequestBody List<MoIllegalInfoVo> moIllegalInfoVoList) {
        return success(service.setTrust(moIllegalInfoVoList, tokenManagerUtil.getCurrentUser().getId()));
    }

    /**
     * 警示榜
     * @return
     */
    @GetMapping("/warn-list")
    public Result<List<WarnList>> warnList() {
        return success(service.warnList());
    }
}

